<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/12/19
 * Time: 10:26
 */
namespace app\tour\controller;

use think\Db;
use think\Request;
use app\tour\model\Album as AlbumModel;
use app\tour\model\Tour as TourModel;
use think\Session;
class Bank extends Common
{
    /*
     * 银行卡信息
     */
    public function bank()
    {
         if (Request::instance()->isAjax()){
            $where['is_del'] = array('eq',0);
            $data = Db::name('tours')->where('tour_id',Session::get('tour_id'))->where($where)->select();
            if(empty($data[0]['tour_bank_card'])){
                 return ['code'=>0,'msg'=>'','data'=>''];
            }else{
                return ['code'=>0,'msg'=>'','data'=>$data];
            }
            
        }else{
           //获取景区信息
            $team = Db::name('tours')->where('tour_id',Session::get('tour_id'))->find();
            $this->assign('team',$team);

            return view();
        }

      
    }

    /*
     * 修改
     */
    public function editTourInfo()
    {
        if (Request::instance()->isAjax()){
            $id = Session::get('tour_id');
            $post = Request::instance()->post();

            $post = $post['data'];

            $eidtData = [

                'tour_bank_card'    => $post['tour_bank_card'],
                'tour_bank_name' =>$post['tour_bank_name'],

            ];

            $res = Db::name('tours')->where('tour_id',$id)->update($eidtData);

            if ($res !== false){

                return ['code'=>0];

            }else{

                return ['code'=>1];

            }

        }
    }

     //添加银行卡
    public function addBank()
    {
        if(Request::instance()->isPost()){
            $post = Request::instance()->post();
            $post = $post['data'];
            $data = [
                'tour_bank_card'=>$post['tour_bank_card'],
                'tour_bank_name'=>$post['tour_bank_name'],
                'bank_user_name'=>$post['bank_user_name'],
            ];
            $res = Db::name('tours')->where('tour_id',Session::get('tour_id'))->update($data);
            if ($res){
        
                return ['code'=>0];

            }else{
                return ['code'=>'添加失败'];
            }
        }
    }

    //修改银行卡
    public function editBank()
    {
        if(Request::instance()->isPost()){
            $post = Request::instance()->post();
            $post = $post['data'];
            $data = [
                 'tour_bank_card'=>$post['tour_bank_card'],
                'tour_bank_name'=>$post['tour_bank_name'],
                'bank_user_name'=>$post['bank_user_name'],
            ];
            $res = Db::name('tours')->where('tour_id',Session::get('tour_id'))->update($data);
            if ($res){
        
                return ['code'=>0];

            }else{
                return ['code'=>'添加失败'];
            }
        }
    }
}